//package RPC.server;
//
//import RPC.constant.Constants;
//import RPC.factory.ZookeeperFactory;
//import RPC.handler.SimpleServerHandler;
//import io.netty.bootstrap.ServerBootstrap;
//import io.netty.channel.*;
//import io.netty.channel.nio.NioEventLoopGroup;
//import io.netty.channel.socket.SocketChannel;
//import io.netty.channel.socket.nio.NioServerSocketChannel;
//import io.netty.handler.codec.DelimiterBasedFrameDecoder;
//import io.netty.handler.codec.Delimiters;
//import io.netty.handler.codec.string.StringDecoder;
//import io.netty.handler.codec.string.StringEncoder;
//import io.netty.handler.timeout.IdleStateHandler;
//import org.apache.curator.framework.CuratorFramework;
//import org.apache.zookeeper.CreateMode;
//
//import java.net.InetAddress;
//import java.util.concurrent.TimeUnit;
//
//public class NettyServer {
//    public static void main(String[] args)  {
//
//        EventLoopGroup parentGroup=new NioEventLoopGroup();
//        EventLoopGroup childGroup=new NioEventLoopGroup();
//        try {
//            ServerBootstrap bootstrap=new ServerBootstrap();
//        bootstrap.group(parentGroup,childGroup);
////        SO_BACKLOG运行128个通道排队 SO_KEEPALIVE心跳机制
//        bootstrap.option(ChannelOption.SO_BACKLOG,128)
//                   .childOption(ChannelOption.SO_KEEPALIVE,false)
//                    .channel(NioServerSocketChannel.class)
//                    .childHandler(new ChannelInitializer<SocketChannel>() {
//                        @Override
//                        protected void initChannel(SocketChannel ch) throws Exception {
//                            ch.pipeline().addLast(new DelimiterBasedFrameDecoder(65535, Delimiters.lineDelimiter()[0]));
//                            ch.pipeline().addLast(new StringDecoder());
//                            ch.pipeline().addLast(new IdleStateHandler(6,4,8, TimeUnit.SECONDS));
//                            ch.pipeline().addLast(new SimpleServerHandler());
//                            ch.pipeline().addLast(new StringEncoder());
//                        }
//                    });
//        final ChannelFuture future = bootstrap.bind(8080).sync();
//            CuratorFramework client = ZookeeperFactory.create();
//            InetAddress netAddress= InetAddress.getLocalHost();
//            System.out.println(netAddress.getHostAddress());
//            client.create().withMode(CreateMode.EPHEMERAL).forPath(Constants.SERVER_PATH+netAddress.getHostAddress());
//
//            future.channel().closeFuture().sync();
//        } catch (Exception e) {
//            e.printStackTrace();
//            parentGroup.shutdownGracefully();
//            childGroup.shutdownGracefully();
//        }
//    }
//}
